
#ifndef __RSA_PUBLIC_KEY_H
#define __RSA_PUBLIC_KEY_H

#include <openssl/rsa.h>
#include "keys.h"
#include "../iface/SSLInterface.h"

class RSAPublicKey : public PublicKey, public EncryptionKey, public CheckingKey
{
   public:
      RSAPublicKey();
      RSAPublicKey(const char *name);
      // Construct a duplicate of the public key
      RSAPublicKey(const RSAPublicKey &other);
      // Construct from PEM format
      RSAPublicKey(const char *pemtext, const char *name);
      // Construct from OpenSSL format
      RSAPublicKey(RSA *pubkey, const char *name);
      // Destroy public key
      ~RSAPublicKey();
      // Get context
      int GetCryptlibContext(CRYPT_CONTEXT *keyContext);
      // Get Encryption context
      int GetCryptlibEncryptionContext(CRYPT_CONTEXT *keyContext);
      // Get Checking context
      int GetCryptlibCheckingContext(CRYPT_CONTEXT *keyContext);
      // Get key components
      int GetCryptlibKeyComponents(CRYPT_PKCINFO_RSA *rsaKey);
      // Get new OpenSSL RSA object
      int GetSSLKeyComponents(RSA **pubkey);
      // Get PEM data
      int GetPEMKeyData(char **pemtext);
      // Get OpenSSH binary blob
      int GetSSHKeyBlob(char **blob, int *reallength);
      // Get OpenSSH text with key label
      int GetSSHKeyBlob(char **textblob, const char *keylabel);
      // Compare key to key
      int CompareKeyEqual(PublicKey *pubkey);
      // Get key type name
      int GetKeyType() { return KEY_TYPE_PUBLIC_RSA; }
      // To import from text - Base64 RAW or PEM
      int ImportKeyFromASCII(const char *text, const char *name);
      // To export to text - Base64 RAW or PEM
      int ExportKeyToASCII(char **text);
      // Import from text with password
      int ImportKeyFromASCIIWithPassword(const char *text, const char *password, const char *name);
      // Export to text with password
      int ExportKeyToASCIIWithPassword(char **text, const char *password);
   private:
      // Copy SSL type public keys
      static int CopyRSASSLPublicKey(RSA *dst, RSA *src);
      RSA *key;
};

#endif
